<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<%@include file="/WEB-INF/taglibs/common/taglibs.jsp" %>
<%@page import="com.serviceprovider.business.module.common.Page"%>
<%@page import="com.serviceprovider.business.module.order.model.Order"%>
<head>
    <title><spring:message code="admin.vieworders.title"/></title>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
    <link rel="stylesheet" href="<c:url value="/css/styles.css"/>"/>
    <script src="<c:url value="/javascripts/common.js"/>" type="text/javascript"></script>
    <link rel="stylesheet"
          href="<c:url value="/javascripts/jscalendar/theme/calendar-system.css"/>"/>
    <script language="javascript"
            src="<c:url value="/javascripts/common.js"/>" type="text/javascript"></script>
    <script src="<c:url value="/javascripts/jscalendar/calendar-cfg.js"/>" type="text/javascript"></script>
    <script src="<c:url value="/javascripts/calendar.js"/>" type="text/javascript"></script>
    <script src="<c:url value="/javascripts/jscalendar/lang/calendar-en.js"/>" type="text/javascript"></script>
    <script src="<c:url value="/javascripts/jscalendar/calendar-setup.js"/>" type="text/javascript"></script>
	<style >
	.pager-page{
		text-decoration: underline;
		color: blue;
		cursor: pointer;
	}
	</style>

</head>

<body>
 <input type="hidden" id="tempRecordSize" name="tempRecordSize" value="${orderList.recordSize}"/>
<c:choose>
    <c:when test="${isAdmin}">
        <%@include file="../top_menu.jsp" %>
    </c:when>
    <c:otherwise>
        <%@include file="/WEB-INF/jsp/serviceprovider/top_menu.jsp" %>
    </c:otherwise>
</c:choose>

<table width="100%">
    <tr>
        <td><c:if test="${isAdmin}">
            <c:import url="/WEB-INF/jsp/menu/view_orders_menu.jsp"/>
        </c:if></td>
    </tr>
    <tr>
        <td>
            <%@include file="/WEB-INF/jsp/include/messages.jsp" %>
            <br/>
        </td>
    </tr>
</table>
<c:choose>
    <c:when test="${isAdmin}">
        <input type="hidden" id="adminUser" value="1"/>
        <c:choose>
            <c:when test="${empty filterList}">
                <form action="view_orders.htm" method="post" id="orderSelectFilterForm">
                    <input type="hidden" id="pageNo" name="pageNo" value="${orderList.pageNumber}"/>
                    <input type="hidden" id="sortColumn" name="sortColumn" value="${orderList.sortColumn}"/>
                    <input type="hidden" id="sortOrder" name="sortOrder" value="${orderList.sortOrder}"/>
                    <input type="hidden" class="recordSize" name="recordSize" value="${orderList.recordSize}"/>
                    
                </form>
                <br/>
            </c:when>
            <c:otherwise>

                <form:form commandName="orderSelectFilterForm" id="orderSelectFilterForm">
                    <input type="hidden" id="pageNo" name="pageNo" value="${orderList.pageNumber}"/>
                    <input type="hidden" id="sortColumn" name="sortColumn" value="${orderList.sortColumn}"/>
                    <input type="hidden" id="sortOrder" name="sortOrder" value="${orderList.sortOrder}"/>
                    <input type="hidden" class="recordSize" name="recordSize" value="${orderList.recordSize}"/>
        
                    <table border="0" cellpadding="4" cellspacing="1" width="400">
                        <tr>
                            <td><spring:message code="admin.vieworders.label.selectfilter"/>:</td>
                            <td><form:select path="filterId">
                                <form:options items="${filterList}" itemValue="id"
                                              itemLabel="name"/>
                            </form:select></td>
                            <td><input type="submit"
                                       class='ui-button ui-state-default ui-corner-all'
                                       value="<spring:message code="admin.vieworders.button.go" />"/>
                            </td>
                        </tr>
                    </table>
                </form:form>
            </c:otherwise>
        </c:choose>
    </c:when>
    <c:otherwise>
        <input type="hidden" id="adminUser" value="0"/>
        <form:form commandName="orderSearchCriteria" id="orderSearchCriteriaForm">
            <input type="hidden" id="pageNo" name="pageNo" value="${orderList.pageNumber}"/>
            <input type="hidden" id="sortColumn" name="sortColumn" value="${orderList.sortColumn}"/>
            <input type="hidden" id="sortOrder" name="sortOrder" value="${orderList.sortOrder}"/>
            <input type="hidden" class="recordSize" name="recordSize" value="${orderList.recordSize}"/>
            <table border="0" cellpadding="4" cellspacing="1" width="400">
                <tr>
                    <td width="170"><spring:message code="admin.vieworders.label.orderdate"/>:</td>
                    <td><component:calendar bindPath="orderDate"/></td>
                </tr>
                <tr>
                    <td width="170"><spring:message code="admin.vieworders.label.ordername"/>:</td>
                    <td colspan="2"><form:input path="orderName" size="24"/></td>
                </tr>
                <tr>
                    <td></td>

                    <td><input type="submit"
                               class='ui-button ui-state-default ui-corner-all'
                               value="<spring:message code="admin.vieworders.button.go" />"/></td>
                </tr>
            </table>
        </form:form>

    </c:otherwise>
</c:choose>
<table width=90% class="formTable" cellspacing="0">
    <tr class="ui-state-default ui-th-column ui-th-ltr">
        <c:if test="${orderList.pageNumber > 1}">
            <td align="left" colspan="10">
            	<a onclick="previous()" href="#" class="mouseEffect">
            		<span class="ui-icon ui-icon-seek-prev" style="float: left;"></span>
            		<spring:message code="admin.viewaction.button.previouspage"/>
           		</a>
        	</td>
        </c:if>
        <c:if test="${orderList.pageNumber < orderList.pagesAvailable}">
            <td colspan="10" align="right">
            	<a onclick="next()" href="#" class="mouseEffect">
            		<span class="ui-icon ui-icon-seek-next" style="float: right;"></span>
            		<spring:message code="admin.viewaction.button.nextpage"/>
            	</a>
            </td>
        </c:if>
    </tr>

</table>
<table class="formTable" width="90%">

    <tr class="formHeader">
        <td colspan="9"><spring:message code="admin.vieworders.label.orders"/></td>
    </tr>
    <tr class="formSubHeader">
        <!-- <th>#</th> -->
        <th><a onclick="sort('name')" href="#"
               class="headerLink" style="cursor: pointer;" title="${orderList.sortOrder}"><spring:message
                code="admin.vieworders.label.orderid"/></a></th>
                
        <%-- <th><a onclick="sort('order_id')" href="#"
               class="headerLink" style="cursor: pointer;" title="${orderList.sortOrder}"><spring:message
                code="admin.vieworders.label.name"/></a></th> --%>
                
        <th><a onclick="sort('user_id')" href="#"
               class="headerLink" style="cursor: pointer;" title="${orderList.sortOrder}"><spring:message
               code="admin.vieworders.label.spid"/></a></th>
                      
        <%-- <th><a onclick="sort('user_id')" href="#"
               class="headerLink" style="cursor: pointer;" title="${orderList.sortOrder}"><spring:message
               code="admin.vieworders.label.serviceprovider"/></a></th> --%>
        <th><a onclick="sort('user_id')" href="#"
               class="headerLink" style="cursor: pointer;" title="${orderList.sortOrder}"><spring:message
               code="admin.vieworders.label.spusername"/></a></th>       
               
        <th><a onclick="sort('user_id')" href="#"
               class="headerLink" style="cursor: pointer;" title="${orderList.sortOrder}"><spring:message
               code="admin.vieworders.label.serviceproviderefin"/></a></th>
        <th><a onclick="sort('user_id')" href="#"
               class="headerLink" style="cursor: pointer;" title="${orderList.sortOrder}"><spring:message
               code="admin.vieworders.label.level1userid"/></a></th>
        
        <th><a onclick="sort('date')" href="#"
               class="headerLink" style="cursor: pointer;" title="${orderList.sortOrder}"><spring:message
                code="admin.vieworders.label.date"/></a></th>
        <th><a onclick="sort('order_status_id')" href="#"
               class="headerLink" style="cursor: pointer;" title="${orderList.sortOrder}"><spring:message
                code="admin.vieworders.label.status"/></a></th>
    </tr>
    <c:choose>
        <c:when test="${empty orderList}">
            <tr>
                <td colspan="9"><spring:message code="admin.vieworders.label.noorderswerefound"/></td>
            </tr>

        </c:when>

        <c:otherwise>
            <c:forEach var="order" items="${orderList.pageItems}" varStatus="i">
                <tr class="tr_record">
                    <%-- <td>${i.index+1}</td> --%>
                    <td><c:choose>
                        	<c:when test="${isAdmin}">
                            	<a href="<c:url value="/admin/order/order.htm?orderId=${order.id}"/>">${order.id}</a>
                        	</c:when>
                        	<c:otherwise>
                            	<a href="<c:url value="/serviceprovider/order/order.htm?orderId=${order.id}"/>">${order.id}</a>
                        	</c:otherwise>
                    	</c:choose>
                   	</td>
                    <%-- <td>
                    	<c:choose>
                        	<c:when test="${isAdmin}">
                            	<a href="<c:url value="/admin/order/order.htm?orderId=${order.id}"/>">${order.name}</a>
                        	</c:when>
                        	<c:otherwise>
                            	<a href="<c:url value="/serviceprovider/order/order.htm?orderId=${order.id}"/>">${order.name}</a>
                        	</c:otherwise>
                    	</c:choose>
                   	</td> --%>
                   	<td>${order.spId}</td>
                    <%-- <td>${order.provider.firstName} ${order.provider.lastName}</td> --%>
                    <td>${order.provider.email}</td>
                    <td>${order.provider.efin}</td>
                    <td>${order.provider.level1User.id}</td>
                    <td><fmt:formatDate value="${order.createdDate}" pattern="dd/MM/yyyy HH:mm:ss"/></td>
                    <td>${order.orderStatus.name}</td>


                </tr>
            </c:forEach>
			<tr>
					<td align="right" colspan="4"><c:if
							test="${orderList.pageNumber > 1}">
							<input type="button" onclick="getPage(1)"
								value="<spring:message	code="admin.view.user.first" />" />
							<input type="button" onclick="previous()"
								value="<spring:message	code="admin.view.user.previous.button" />" />
						</c:if></td>
					<td colspan="4" align="left"><c:if
							test="${orderList.pageNumber < orderList.pagesAvailable}">
							<input type="button" onclick="next()"
								value="<spring:message code="admin.view.user.next.button" />" />
							<input type="button"
								onclick="getPage(${orderList.pagesAvailable})"
								value="<spring:message code="admin.view.user.last" />" />

						</c:if></td>
			</tr>
			<tr>
		<td colspan="8" align="center">
			Page Size : <select id="pageSize" name="pageSize" onchange="getPageWithPageSize()">
			<option value="5">5</option>
			<option value="10">10</option>
			<option value="15">15</option>
			<option value="20">20</option>
			<option value="25">25</option>
			<option value="30">30</option>
			<option value="35">35</option>
		</select>
			<%
				Page<Order> orderPage = (Page<Order>)request.getAttribute("orderList");
				for(int i=1; i<= orderPage.getPagesAvailable(); i++){
					if(i== orderPage.getPageNumber()){
				%>
					<span ><% out.print(i);  %></span>
					<% }else{ %>
					<span class="pager-page" onclick="getPage(<%= i %>)"><% out.print(i); %></span>
				<%
					}
				}
			%>
		<div style="float:right;">view ${orderList.pageNumber} of ${orderList.pagesAvailable}</div>	
		</td>
		</tr>
        </c:otherwise>

    </c:choose>
</table>
<table width=90% class="formTable" cellspacing="0">
    <tr class="ui-state-default ui-th-column ui-th-ltr">
        <c:if test="${orderList.pageNumber > 1}">
            <td align="left" colspan="10">
            	<a onclick="previous()" href="#" class="mouseEffect">
            		<span class="ui-icon ui-icon-seek-prev" style="float: left;"></span>
            		<spring:message code="admin.viewaction.button.previouspage"/>
           		</a>
         	</td>
        </c:if>
        <c:if test="${orderList.pageNumber < orderList.pagesAvailable}">
            <td colspan="10" align="right">
            	<a onclick="next()" href="#" class="mouseEffect">
            		<span class="ui-icon ui-icon-seek-next" style="float: right;"></span>
            		<spring:message code="admin.viewaction.button.nextpage"/>
           		</a>
          	</td>
        </c:if>
    </tr>

</table>

<script language="javascript" type="text/javascript">
	$(document).ready(function(){
		$("#pageSize").val($("#tempRecordSize").val());
	});
    function next() {
        var pageNo = document.getElementById("pageNo");
        var pageNoInt = parseInt(pageNo.value);
        pageNoInt += 1;
        pageNo.value = pageNoInt;
        if (document.getElementById("adminUser").value == '1')
            document.forms['orderSelectFilterForm'].submit();
        else
            document.forms['orderSearchCriteriaForm'].submit();
    }

    function previous() {
        var pageNo = document.getElementById("pageNo");
        var pageNoInt = parseInt(pageNo.value);
        pageNoInt -= 1;
        pageNo.value = pageNoInt;
        if (document.getElementById("adminUser").value == '1')
            document.forms['orderSelectFilterForm'].submit();
        else
            document.forms['orderSearchCriteriaForm'].submit();
    }
    function sort(columnName) {
        document.getElementById("sortColumn").value = columnName;
        if (document.getElementById("adminUser").value == '1')
            document.forms['orderSelectFilterForm'].submit();
        else
            document.forms['orderSearchCriteriaForm'].submit();
    }

    function getPage(page) {
		document.getElementById("pageNo").value = page;
		if(	document.getElementById("adminUser").value=='1')
			document.forms['orderSelectFilterForm'].submit();
		else
			document.forms['orderSearchCriteriaForm'].submit();	
	}

	function getPageWithPageSize(){
		document.getElementById("pageNo").value = 1;
		$(".recordSize").each(function(){
			$(this).val($("#pageSize").val());
			});
		if(	document.getElementById("adminUser").value=='1')
			document.forms['orderSelectFilterForm'].submit();
		else
			document.forms['orderSearchCriteriaForm'].submit();
	}
</script>
<%@include file="/WEB-INF/jsp/include/footer.jsp" %>
</body>
</html>
